class List < ActiveRecord::Base
  has_many :entries, :dependent => :destroy
  belongs_to :user
  
  validates_presence_of :title, :user_id
  validates_uniqueness_of :title, :scope => :user_id
  
  def unread_entries
    Entry.find(:all, :conditions => {:list_id => self, :status => 1}, :order => 'updated_at DESC')
  end
  
  def read_entries(limit = 10)
    Entry.find(:all, :conditions => {:list_id => self, :status => 2}, :order => 'updated_at DESC', :limit => limit)
  end
  
  # Used by Next in List feature
  def first_entry
    Entry.find(:first, :conditions => {:list_id => self, :status => 1}, :order => 'updated_at DESC')
  end
end
